import {BaseModel} from "../BaseModel";

export class Book extends BaseModel{

    constructor(){
        super();
        this.symbolName = "Book";
        this.tableName = "t_book";
        this.id = '';//主键id
        this.name = '';//名称
        this.publisherId = '';//教材版本id
        this.brief = '';//简介
        this.authPeriod = '';//授权到期时间
        this.sortIndex = -1;//排序
        this.thumb = '';//缩略图，本地地址
        this.isAuthorize = '';//是否授权
        this.version = -1;//版本号
        this.reverse1 = '';//最近一次访问书本时间
        this.reverse2 = '';//备用字段2
        this.reverse3 = '';//备用字段3
    }

    dbMapper(){
        return {
            id: 'id',
            name: 'name',
            publisherId: 'publisher_id',
            brief: 'brief',
            authPeriod: 'auth_period',
            sortIndex: 'sort_index',
            thumb: 'thumb',
            isAuthorize: 'is_authorize',
            version: 'version',
            reverse1: 'reverse1',
            reverse2: 'reverse2',
            reverse3: 'reverse3'
        }
    }

    /**
     * 输出转换
     * @param obj
     * @returns {Book}
     */
    mappingModel(obj){
        let book = new Book();
        book.id = obj.id ? obj.id : ''
        book.name = obj.name ? obj.name : ''
        book.publisherId = obj.publisher_id ? obj.publisher_id : ''
        book.brief = obj.brief ? obj.brief : ''
        book.authPeriod = obj.auth_period ? obj.auth_period : ''
        book.sortIndex = obj.sort_index ? obj.sort_index : -1
        book.thumb = obj.thumb ? obj.thumb : ''
        book.isAuthorize = obj.is_authorize ? obj.is_authorize : ''
        book.version = obj.version ? obj.version : -1
        book.reverse1 = obj.reverse1 ? obj.reverse1 : ''
        book.reverse2 = obj.reverse2 ? obj.reverse2 : ''
        book.reverse3 = obj.reverse3 ? obj.reverse3 : ''
        return book;
    }
}
